﻿using Ewell.BizComponent.UI.Charge.ViewModel;
using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ewell.BizComponent.UI.Charge.Windows
{
    /// <summary>
    /// OnlinePayWindow.xaml 的交互逻辑
    /// </summary>
    public partial class OnlinePayWindow : MetroWindow
    {
        private OnlinePayVm _onlinePayVm;
        public OnlinePayVm onlinePayVm
        {
            get => _onlinePayVm;
            set
            {
                if (_onlinePayVm != value)
                {
                    _onlinePayVm = value;
                    OnPropertyChanged(nameof(onlinePayVm));
                }
            }
        }
        public OnlinePayWindow()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        public OnlinePayWindow(OnlinePayVm onlinePayVm):this()
        {
            this.onlinePayVm= onlinePayVm;
            this.onlinePayVm.localWindows = this;
            onlinePayView.onlinePayVm= onlinePayVm;
        }

        private TaskCompletionSource<bool> continueTcs = null;
        public bool payWaitState { get; set; }

        /// <summary>
        /// 支付
        /// </summary>
        internal void PayAll()
        {
            onlinePayView.PayAll();
        }
        /// <summary>
        /// 退款
        /// </summary>
        internal void RefundAll()
        {
            this.Loaded += async (s, e) =>
            {
                await Task.Run(() =>
                {
                    onlinePayView.RefundAll();
                });
            };
            this.ShowDialog();
        }
    }
}
